package com.example.demo.config;


import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

public class Swagger2Config {

    /**
     * 前台API分组
     *
     * @return
     */
    @Bean(name = "indexApi")
    public Docket indexAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("系统API分组")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("xyz.erupt"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 后台API分组
     *
     * @return
     */
    @Bean(name = "adminApi")
    public Docket adminAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台API分组")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger-bootstrap-ui RESTFUL APIs")
                .description("Swagger-bootstrap-ui")
                .termsOfServiceUrl("http://localhost:8080")
                .contact(new Contact("youli", "youli.top", "27855162@qq.com"))
                .license("Apache License Version 2.0")
                .version("1.0.0")
                .build();

    }
}
